package com.itheima.mapper;

import com.itheima.pojo.Addressbook;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Envy
 */
@Mapper
public interface AddressbookMapper {
    /**
     * 设置默认收货地址
     */
    Integer defaultAddressBook(Addressbook addressbook);

    /**
     * 获取默认收货地址
     */
    @Select("select * from addressbook where isDefault= 1 ")
    Addressbook selectIsDefault();

    /**
     * 获取收货地址列表
     */
    @Select("select * from addressbook ")
    List<Addressbook> selectAddressBook();

    /**
     * 根据id获取收货地址
     */
    @Select("select * from addressbook where id=#{id}")
    Addressbook selectById(String id);

    /**
     * 添加收货地址
     */
    @Insert("insert into addressbook (id,userId,consignee,phone,sex,detail,label)values (#{id},#{userId},#{consignee},#{phone},#{sex},#{detail},#{label})")
    int addAddressBook(Addressbook addressbook);

    /**
     * 删除收货地址
     */
    @Delete("delete from addressbook where id=#{id}")
    int deleteAddressBook(String id);

        /**
     * 修改收货地址
     */
    int updateAddressBook(Addressbook addressbook);
}
